//
//  KBStatusForwardCell.swift
//  KimboWeiBoSwift
//
//  Created by kimbo on 15/12/22.
//  Copyright © 2015年 kimbo. All rights reserved.
//

import UIKit

/// 转发微博的cell
class KBStatusForwardCell: KBStatusCell {
    
    // MARK: - 属性
    // 覆盖父类的属性:1.要加override 2.必须实现属性监视器 3.先执行父类的属性监视器，再实现子类的属性监视器
    override var status: KBStatus? {
        didSet {
            if let forwardStatus = status?.retweeted_status {
                forwardLabel.text = "@\(forwardStatus.user?.screen_name): \(forwardStatus.text)"
            }
        }
    }

    // MARK: - 方法
    override func setupUI() {
        super.setupUI()
        
        contentView.addSubview(bgButton)
        contentView.addSubview(forwardLabel)
        
        contentView.sendSubviewToBack(bgButton)
        
        //添加约束
        /* 转发微博的背景按钮 */
        bgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        
        bgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        /* 转发微博的文本 */
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bgButton, size: nil, offset: CGPoint(x: 8, y: 8))
        
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        /* 转发微博的配图 */
        let con = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: 8))
        
        pictureViewWidthCon = pictureView.ff_Constraint(con, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCon = pictureView.ff_Constraint(con, attribute: NSLayoutAttribute.Height)
    }

    // MARK: - 懒加载
    /* 转发微博的背景按钮 */
    private lazy var bgButton: UIButton = {
        let bgButton = UIButton()
        
        bgButton.backgroundColor = UIColor(white: 0.88, alpha: 1)
        
        return bgButton
    }()
    
    /* 转发微博的文本 */
    private lazy var forwardLabel: UILabel = {
        let forwardLabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        
        forwardLabel.numberOfLines = 0
        
        return forwardLabel
    }()

}
